import common from './common.js'
import md5 from './md5.js'
import cookie from './cookie.js'
const request = {}
const headers = {}
const PORT1 = '/baseinfo'
request.globalRequest = (url, method, data) => {	
    data.str = md5.state.getStr();	
    data.signature= md5.state.getSignature();	
	data.token = uni.getStorageSync('token');	
    return uni.request({
        url: common + url,
        method,
        data: data,
        dataType: 'json',
        header: {
			'content-type': 'application/x-www-form-urlencoded'
		}
    }).then(res => {
        if (res[1].statusCode == 200 && res[1].data.code == 0) {
            return res[1]
        } else {
            throw res[1].data.msg
        }
    }).catch(parmas => {
		switch (parmas.code) {
			case 401:
				uni.clearStorageSync()
				break
			default:
				uni.showToast({
					title: parmas.message,
					icon: 'none'
				})
				return Promise.reject()
				break
		}
　　})
 } 
export default request